package core;

public class RemoveItemCommand extends Command
{
	private ItemBarcode barcode;
	private ItemManager im;
	private ProductContainer parent;
	private CoreFacade core;
	
	/**
     * Removes the item from the system, and adds to the usedItems
     * @param item unique item which we are removing
     */
	public RemoveItemCommand(Item i)
	{
		super();
		core = CoreFacade.getInstance();
		im = core.getIM();
		item = i;
		parent = i.getProductContainer();
	}
	
	@Override
	public Item execute()
	{
    	try{
    		 im.removeItem(item);
    	}
    	catch(Exception e)
    	{
    		return null;
    	}
    	core.sendNotify(item);
    	return item;
	}

	@Override
	public Item undo()
	{
		try {
			im.undoRemoveItem(item, parent);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		core.sendNotify(item);
		return item;
	}
	
	public ProductContainer getContainer()
	{
		return parent;
	}
}



